package com.example.demos.util;

import java.lang.reflect.Field;

public class CheckQueryParams {
    public static boolean checkEmpty(Object t,int num) throws IllegalAccessException {
        boolean isEmpty = false;
        Class<?> aClass = t.getClass();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (int i = 0; i < num; i++) {
            declaredFields[i].setAccessible(true);
            if (declaredFields[i].get(t) == null){
                return true;
            }
        }
        return isEmpty;
    }

    public static boolean checkEmpty(Object t) throws IllegalAccessException {
        boolean isEmpty = false;
        Class<?> aClass = t.getClass();
        for (Field declaredField : aClass.getDeclaredFields()) {
            declaredField.setAccessible(true);
            if (declaredField.get(t) == null){
                return true;
            }
        }
        return isEmpty;
    }

    public static Object filterSpace(Object o) throws IllegalAccessException {
        Class<?> aClass = o.getClass();
        for (Field declaredField : aClass.getDeclaredFields()) {
            declaredField.setAccessible(true);
            if (declaredField.get(o) != null){
                if (String.class.isAssignableFrom(declaredField.getType())){
                    declaredField.set(o,declaredField.get(o).toString().trim());
                }
            }
        }
        return o;
    }
}
